import Vue from 'vue'
import VueRouter from 'vue-router'
import Dashboard from '@/views/Dashboard';
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/dashboard',
  },
  {
    path: '/dashboard',
    name: 'dashboard',
    component: Dashboard,
    children: [
      { path: '/dashboard', redirect: '/dashboard/home' },
      {
        path: 'home', name: 'home', component: () => import('@/views/Dashboard/Home/Home.vue'),
        children: [
          { path: '/dashboard/home', redirect: '/dashboard/home/goodhome' },
          { path: 'goodhome', name: 'goodhome', component: () => import('@/views/Dashboard/Home/GoodHome/GoodHome.vue') },
          { path: 'goodsearch', name: 'goodsearch', component: () => import('@/views/Dashboard/Home/GoodSearch/GoodSearch.vue') },
          { path: 'goodlist', name: 'goodlist', component: () => import('@/views/Dashboard/Home/GoodList/GoodList.vue') }
        ]
      },
      { path: 'login', name: 'login', component: () => import('@/views/Dashboard/Login/Login.vue') },
      { path: 'register', name: 'register', component: () => import('@/views/Dashboard/Register/Register.vue') },
      { path: 'shopcard', name: 'shopcard', component: () => import('@/views/Dashboard/ShopCard/ShopCard.vue') },
      { path: 'detail/:id', name: 'detail', component: () => import('@/views/Dashboard/Detail/Detail.vue') }
    ]
  },
  {
    path: '*',
    redirect: '/dashboard',
  },
]



let originPush = VueRouter.prototype.push;
let originReplace = VueRouter.prototype.replace;

//手写push replace 防止重复进入报错
VueRouter.prototype.push = function (location, resolve, reject) {
  if (resolve && reject) {
    originPush.call(this, location, resolve, reject)
  }
  else {
    originPush.call(this, location, () => { }, () => { })

  }
}

VueRouter.prototype.replace = function (location, resolve, reject) {
  if (resolve && reject) {
    originReplace.call(this, location, resolve, reject)
  }
  else {
    originReplace.call(this, () => { }, () => { })

  }
}


const router = new VueRouter({
  routes
})

export default router
